<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.util.*, model.*" %>
<%@ page import="static utilities.MyConst.CART" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户购物车信息</title>
</head>
<body>
<%
    ShoppingCart cart = (ShoppingCart) session.getAttribute(CART);
    if (cart == null) {
        cart = new ShoppingCart();
        session.setAttribute(CART, cart);
    }
    ArrayList<GoodsItem> items = new ArrayList<>(cart.getItems());
%>
<table>
    <tr>
        <td style="width: 50px">数量</td>
        <td style="width: 80px">商品</td>
        <td style="width: 80px">价格</td>
        <td style="width: 80px">小计</td>
        <td style="width: 80px">是否删除</td>
    </tr>

    <c:forEach items="<%=items%>" var="goodsItem">
        <tr>
            <td>${goodsItem.quantity}
            </td>
            <td>${goodsItem.product.pname}
            </td>
            <td>${goodsItem.product.price}
            </td>
            <td>${((goodsItem.product.price * goodsItem.quantity * 100 + 0.5)) / 100.00}
            </td>
            <td><a href="deleteItem?id=${goodsItem.product.pid}">删除</a></td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="4" style="text-align: right">总计:<%=cart.getTotal()%>
        </td>
    </tr>
</table>
<a href="shopping.jsp">返回继续购物</a>

<a href="deleteAllCart">清空购物车</a>

</body>
</html>
